package com.example.mybatispermission.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mybatispermission.entry.Role;
import com.example.mybatispermission.entry.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Insert("insert into user_role values (#{user.id}, #{role.id})")
    void bindRole(@Param("user") User user, @Param("role") Role role);
    @Insert("<script>" +
            "insert into user_role values " +
            "<foreach item='role' index='index' collection='list' separator=','>" +
            "(#{user.id}, #{role.id})" +
            "</foreach>" +
            "</script>")
    void bindRoles(@Param("user") User user, @Param("list") List<Role> list);
    @Delete("delete from user_role where uid=#{user.id}")
    void clearRoles(@Param("user") User user);
}
